package com.ssd.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.ssd.entity.SkuClassEntity;
import com.ssd.entity.SkuEntity; // 假设有一个 SkuEntity 类
import org.apache.ibatis.annotations.*;

import java.util.Map;

@Mapper
public interface SkuClassDao extends BaseMapper<SkuClassEntity> {

    @Select("<script>" +
            "SELECT *" +
            "FROM tb_sku_class" +
            "<where> " +
            "<if test='skuClassName != null and skuClassName != \"\"'> " +

            "class_name LIKE CONCAT('%', #{skuClassName}, '%') " +
            "</if> " +
            "</where> " +
            "ORDER BY class_id " +
            "</script>")
    @Results({
            @Result(column = "class_id", property = "classId"),
            @Result(column = "parent_id", property = "parentId"),
            @Result(column = "class_name", property = "className")
            // 根据 SkuEntity 的属性添加更多的 Result 映射
    })
    Page<Map<String, Object>> getSkuClassList(Page<?> page, String skuClassName);

    @Select("SELECT * FROM tb_sku_class WHERE class_id = #{classId}")
    @Results({
            @Result(column = "class_id", property = "classId"),
            @Result(column = "parent_id", property = "parentId"),
            @Result(column = "class_name", property = "className")
            // 根据 SkuEntity 的属性添加更多的 Result 映射
    })
    SkuClassEntity selectSkuClassByClassId(Long classId);

    /**
     * 新增商品类型
     *
     * @param skuClass 商品类型
     * @return 结果
     */

    @Insert("INSERT INTO tb_sku_class (class_id, parent_id, class_name) " +
            "VALUES (#{classId}, #{parentId}, #{className})")
    public int insertSkuClass(SkuClassEntity skuClass);

    /**
     * 修改商品类型
     *
     * @param skuClass 商品类型
     * @return 结果
     */
    @Update("UPDATE tb_sku_class SET parent_id=#{parentId}, class_name=#{className} " +
            "WHERE class_id=#{classId}")
    public int updateSkuClass(SkuClassEntity skuClass);

    /**
     * 批量删除商品类型
     *
     * @param classIds 需要删除的商品类型主键集合
     * @return 结果
     */
    @Delete("<script>" +
            "DELETE FROM tb_sku_class" +
            "<where>" +
            "class_id IN" +
            "<foreach item='id' index='index' collection='array' open='(' separator=',' close=')'>" +
            "#{id}" +
            "</foreach>" +
            "</where>" +
            "</script>")
    public int deleteSkuClassByClassIds(Long[] classIds);;

    /**
     * 删除商品类型信息
     *
     * @param classId 商品类型主键
     * @return 结果
     */
    @Delete("DELETE FROM tb_sku_class WHERE class_id = #{classId}")
    public int deleteSkuClassByClassId(Long classId);
}